package com.shengde.jinwawaforleader.views;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.shengde.jinwawaforleader.R;

/**
 * Created by Chason on 2016/10/25.
 */

public class ModifyTeaStuPopupWindow extends PopupWindow {
    View mPopView; //popuwindow的 布局页面
    public TextView tv_video_babydiary_share;  //布局页面的分享
    public TextView tv_modify;
    public TextView tv_video_babydiary_delete;//布局页面的删除
    public TextView tv_video_babydiary_cancle;//布局页面的取消
    public TextView tv_binding_id_card;//tv_binding_id_card

    public ModifyTeaStuPopupWindow(Context context, View.OnClickListener itemsOnClick) {
        super(context);
        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        mPopView = inflater.inflate(R.layout.modify_teastu_pop_window, null);

        tv_video_babydiary_share = (TextView) mPopView.findViewById(R.id.tv_video_babydiary_share);
        tv_modify = (TextView) mPopView.findViewById(R.id.tv_modify);
        tv_video_babydiary_delete = (TextView) mPopView.findViewById(R.id.tv_video_babydiary_delete);
        tv_video_babydiary_cancle = (TextView) mPopView.findViewById(R.id.tv_video_babydiary_cancle);
        tv_binding_id_card = (TextView) mPopView.findViewById(R.id.tv_binding_id_card);


        //取消按钮
        tv_video_babydiary_cancle.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                //销毁弹出框
                dismiss();
            }
        });
        //设置按钮监听
        tv_video_babydiary_share.setOnClickListener(itemsOnClick);
        tv_modify.setOnClickListener(itemsOnClick);
        tv_binding_id_card.setOnClickListener(itemsOnClick);
        tv_video_babydiary_delete.setOnClickListener(itemsOnClick);

        //设置SelectPicPopupWindow的View
        this.setContentView(mPopView);
        //设置SelectPicPopupWindow弹出窗体的宽
        this.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
        //设置SelectPicPopupWindow弹出窗体的高
        this.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
        //设置SelectPicPopupWindow弹出窗体可点击
        this.setFocusable(true);
        //设置SelectPicPopupWindow弹出窗体动画效果
        this.setAnimationStyle(R.style.mypopwindow_anim_style);
        //实例化一个ColorDrawable颜色为半透明
        ColorDrawable dw = new ColorDrawable(Color.TRANSPARENT);
        //设置SelectPicPopupWindow弹出窗体的背景
        this.setBackgroundDrawable(dw);
        //mPopView添加OnTouchListener监听判断获取触屏位置如果在选择框外面则销毁弹出框
        mPopView.setOnTouchListener(new View.OnTouchListener() {

            public boolean onTouch(View v, MotionEvent event) {

                int height = mPopView.findViewById(R.id.pop_layout).getTop();
                int y=(int) event.getY();
                if(event.getAction()==MotionEvent.ACTION_UP){
                    if(y<height){
                        dismiss();
                    }
                }
                return true;
            }
        });

    }
}
